Ext.namespace('Divo');
Ext.namespace('Divo.app');

Divo.app.SupplierForm = Ext.extend(Divo.Base.EditForm, {
      fields : new Ext.util.MixedCollection(),
      dataRecordMeta : Ext.data.Record.create([{
            name : "_p_record_status",
            type : "string"
          }, {
            name : "id",
            type : "float"
          }, {
            name : "name",
            type : "string"
          }, {
            name : "typeCode",
            type : "string"
          }, {
            name : "depiction",
            type : "string"
          }, {
            name : "shortName",
            type : "string"
          }, {
            name : "address",
            type : "string"
          }, {
            name : "tel",
            type : "string"
          }, {
            name : "person",
            type : "float"
          }, {
            name : "country",
            type : "string"
          }]),
      initComponent : function() {
        var me = this;
        var tn = 1;

        this.fields.add("_p_record_status", new Ext.form.Hidden({
                  name : "_p_record_status"
                }));
        this.fields.add("id", new Ext.form.Hidden({
                  name : "id",
                  dataIndex : "id",
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("typeCode", new Ext.form.Hidden({
                  name : "typeCode",
                  dataIndex : "typeCode",
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("name", new app.base.TextField({
                  name : "name",
                  dataIndex : "name",
                  fieldLabel : "供应商名",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("depiction", new app.base.TextArea({
                  name : "depiction",
                  dataIndex : "depiction",
                  fieldLabel : "供应商描述",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("shortName", new app.base.TextField({
                  name : "shortName",
                  dataIndex : "shortName",
                  fieldLabel : "简称",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("address", new app.base.TextField({
                  name : "address",
                  dataIndex : "address",
                  fieldLabel : "地址",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("tel", new app.base.NumberField({
                  name : "tel",
                  dataIndex : "tel",
                  fieldLabel : "电话",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("person", new app.base.TextField({
                  name : "person",
                  dataIndex : "person",
                  fieldLabel : "联系人",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        this.fields.add("country", new app.base.TextField({
                  name : "country",
                  dataIndex : "country",
                  fieldLabel : "国别",
                  allowBlank : false,
                  labelSeparator : ":*",
                  tabIndex : tn++,
                  width : 150,
                  insert_allowed : true,
                  update_allowed : true
                }));
        var recordDef = Ext.data.Record.create([{
              name : "id",
              type : "float"
            }, {
              name : "name",
              type : "string"
            }, {
              name : "code",
              type : "string"
            }]);
        var storeDs = new Ext.data.Store({
              proxy : new Ext.data.HttpProxy({
                    url : 'supplier/query_type'
                  }),
              reader : new Ext.data.JsonReader({
                    root : 'rows',
                    totalProperty : 'totalCount',
                    id : 'id'
                  }, recordDef)
            });
        var t1 = '<tpl for=\".\">';
        var t2 = '</tpl>';
        var resultTpl = [t1 + '<div class="x-combo-list-item">',
            '<b>{code}--{name}</b><br>', '</div>' + t2].join('');
        this.fields.add("typeG", new app.base.ComboBox({
                  fieldLabel : '选择类型',
                  name : 'typeG',
                  tabIndex : tn++,
                  store : storeDs,
                  displayField : 'code',
                  dataIndex : 'typeG',
                  mode : 'remote',
                  typeAhead : false,
                  forceSelection : true,
                  loadingText : '正在搜索...',
                  listWidth : 300,
                  labelSeparator : ":*",
                  width : 150,
                  minChars : 0,
                  allowBlank : false,
                  tpl : resultTpl,
                  insert_allowed : true,
                  update_allowed : true,
                  onSelect : function(record) {
                    var data = record.data;
                    me.setFieldValue("typeG", data.name);
                    me.setFieldValue("typeCode", data.code);
                    this.onTriggerClick();
                  }
                }));
        Ext.apply(this, {
              items : [this.fields.get("_p_record_status"), {
                layout : "form",
                columnWidth : 1,
                labelAlign : "right",
                labelWidth : 100,
                items : [this.fields.get("id"), this.fields.get("typeCode"),
                    this.fields.get("name"), this.fields.get("typeG"),
                    this.fields.get("shortName"), this.fields.get("address"),
                    this.fields.get("tel"), this.fields.get("person"),
                    this.fields.get("country"), this.fields.get("depiction")]
              }],
              border : false,
              frame : true,
              firstFocusFieldName : "name"
            });

        Divo.app.SupplierForm.superclass.initComponent.apply(this, arguments);
      }

      ,
      onRender : function() {
        Divo.app.SupplierForm.superclass.onRender.apply(this, arguments);
      },
      newDataRecord : function() {
        return new this.dataRecordMeta({
              _p_record_status : "insert",
              id : "",
              name : "",
              sId : "",
              state : ""
            });
      }

    });
Ext.reg("Divo.app.SupplierForm", Divo.app.SupplierForm);